package com.example.deploysinggle.test1.controller;

import com.example.deploysinggle.test1.common.general.APIConfiguration;
import com.example.deploysinggle.test1.common.general.DeafaltApiCheckedInterface;
import com.example.deploysinggle.test1.common.req.BaseApiRequest;
import com.example.deploysinggle.test1.common.resp.CommonSingleResponse;
import com.example.deploysinggle.test1.common.util.ResponseUtil;
import com.example.deploysinggle.test1.interface1.ABC;
import com.example.deploysinggle.test1.mybagenera.entity.SyncDataVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Administrator
 * @version 1.0
 * @description: TODO
 * @date 2024/11/28 18:07
 */
@Slf4j
@RestController
public class TestController implements DeafaltApiCheckedInterface {

   @Autowired
   private APIConfiguration apiConfiguration;

//    @Value("${aa.bb}")
//    private Long bb;

    @RequestMapping("/test")
    public CommonSingleResponse<Map<Integer, List<String>>> test(@RequestBody BaseApiRequest baseApiRequest) throws Exception {
        handle(baseApiRequest);
        List<ABC.Aa> list = getList();
//        Map<String, List<String>> collect1 = list.stream().collect(Collectors.groupingBy(Aa::getId)).entrySet().stream().collect(Collectors
//                .toMap(Map.Entry::getKey, entry -> entry.getValue().stream().map(Aa::getUrl).collect(Collectors.toList())));


        // 第二种方式   简单方式：
        Map<Integer, List<String>> collect1 = list.stream().collect(Collectors.groupingBy(ABC.Aa::getId,Collectors.mapping(ABC.Aa::getUrl,Collectors.toList())));
       //完成一次请求 设置redi初始值以及 过期时间
        setRandomUsedTimes(baseApiRequest.getRandom());
        return ResponseUtil.success(collect1);
    }
// get请求

    @RequestMapping("/test1")
    public Map<Integer, List<String>> test1() throws Exception {
        List<ABC.Aa> list = getList();
//        Map<String, List<String>> collect1 = list.stream().collect(Collectors.groupingBy(Aa::getId)).entrySet().stream().collect(Collectors
//                .toMap(Map.Entry::getKey, entry -> entry.getValue().stream().map(Aa::getUrl).collect(Collectors.toList())));


        // 第二种方式   简单方式：
        Map<Integer, List<String>> collect1 = list.stream().collect(Collectors.groupingBy(ABC.Aa::getId,Collectors.mapping(ABC.Aa::getUrl,Collectors.toList())));
        return collect1;
    }

//    @RequestMapping("/testAbstract")
//    public CommonSingleResponse<Boolean> testAbstract(@RequestBody BaseApiRequest baseApiRequest) throws Exception {
//         List<SyncDataVo> syncDataVoList = getSyncDataVoList();
//        syncDataVoList.forEach(
//                s->{
//                    try {
//                        //获得该实例系统
//                         SyncDatEnum type = SyncDatEnum.getByOriginalType(s.getOriginalType());
//                        AbstractSyncDataService.distribute(,type,)
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                    }
//                }
//        );
//
//        setRandomUsedTimes(baseApiRequest.getRandom());
//        return ResponseUtil.success(Boolean.TRUE);
//    }



    List<ABC.Aa> getList(){
        List<ABC.Aa> aa=new ArrayList<>();
        aa.add(ABC.Aa.builder().id(1).url("/test1").build());
        aa.add(ABC.Aa.builder().id(1).url("/bb").build());
        aa.add(ABC.Aa.builder().id(2).url("/cc").build());
        aa.add(ABC.Aa.builder().id(2).url("/dd").build());
        return aa;
    }
    // 不同系统的要做不同的操作
    List<SyncDataVo> getSyncDataVoList(){
        List<SyncDataVo> reList = new ArrayList<>();

             SyncDataVo build1 = SyncDataVo.builder()
                    .id(1)
                    .originalType("hr")
                    .build();
        SyncDataVo build2 = SyncDataVo.builder()
                .id(2)
                .originalType("oa")
                .build();
        SyncDataVo build3 = SyncDataVo.builder()
                .id(3)
                .originalType("others")
                .build();
            reList.add(build1);
            reList.add(build2);
            reList.add(build3);

        return reList;
    }

    public static void main(String[] args) {
        List<String> list=new ArrayList<>();
        list.add("/test/urlTest");

        String str="/test/urlTest";
        System.out.println(list.contains(str));
    }


    @Override
    public APIConfiguration getApiConfiguration() {
        return apiConfiguration;
    }

}
